package com.common.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;

import com.common.pager.Pager;

import java.util.ArrayList;

/**
 * Created by xiaobinwang on 2017/8/16.
 */

public abstract class BaseListRecyclerAdapter<T> extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    
    protected Context mContext;
    
    public BaseListRecyclerAdapter(Context context) {
        this.mContext = context;
    }
    
    public BaseListRecyclerAdapter(Context context, ArrayList<T> datas) {
        this.mContext = context;
        this.mDatas = datas;
    }
    
    public ArrayList<T> mDatas = new ArrayList<>();
    
    public void setDatas(ArrayList<T> data, Pager page) {
        page.computer(data);
        if (page.isFirst) {
            mDatas.clear();
            mDatas.addAll(data);
        } else {
            mDatas.addAll(data);
        }
        notifyDataSetChanged();
    }
    
    public T getItem(int position) {
        if (mDatas == null) {
            return null;
        }
        
        return mDatas.get(position);
    }
    
    @Override
    public int getItemCount() {
        return mDatas == null ? 0 : mDatas.size();
    }
}
